#ifndef __BGM_CURTAIN_PLAY__H__
#define __BGM_CURTAIN_PLAY__H__

#include <mutex>
#include "json.h"
#include <string>
#include <vector>
#include <functional>
#include "Thread/Thread.h"
#include "Poller/Timer.h"
#include "StreamComposeMgr.h"
#include "StreamerDownloadOnlineFile.h"
#include "DiskController.h"

using namespace std;

namespace Media{

#define BGM_ROOT_DIR "/bgm/"

#define BGM_DESCRIBE "/describe"


class BgmCurtainPlay
{ 
public: 
	static BgmCurtainPlay* instance();

	bool playBgmCurtain(std::string rootPath = "");

	bool stopBgmCurtain();

	bool stopUsbcardBgmCurtain();

	bool playNextBgm();

public:
	BgmCurtainPlay();
	~BgmCurtainPlay();
	
private:

	bool startBgmDeal();

	bool bgmDescribeCheckout(Json::Value& streamerTable, std::string url, std::string fileName);
	
    bool updateBgmPlay();

    void downloadResult(bool result, std::string httpPath, std::string localPath);

    bool changeDescribeInfo(std::string url, std::string fileName);

    bool getDownloadUrl(std::vector<std::string>& urls);

    bool compareMd5(std::string filename, const char *md5);

private:
    static BgmCurtainPlay*			            sm_streamercurtainPlayIns;

	static std::mutex 			                sm_insMutex;
	
	bool 										m_streamerPlay = false;
	
	bool										m_streamer = false;

	mutex 										m_stopstreamLock;

	bool										m_streamerThread = false;

	uint16_t                                    m_curPlayIndex = 0;

	mutex                                       m_palyDscribeMutex;

	std::string                                 m_curfilePath;

	std::string                                 m_curfileMd5;
	
	std::string 								m_streamerPath;

	std::string 								m_streamerDescPath;

	std::string 								m_rootPath;

	std::string                                 m_playPattern;

	Json::Value                                 m_bgmListTable;

};

}//namespace Media

#endif





